package com.ruoyi.house_sale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.CustPlan;
import com.ruoyi.house_sale.service.ICustPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户意向Controller
 * 
 * @author ruoyi
 * @date 2022-04-09
 */
@RestController
@RequestMapping("/house_sale/CustPlan")
public class CustPlanController extends BaseController
{
    @Autowired
    private ICustPlanService custPlanService;

    /**
     * 查询客户意向列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustPlan custPlan)
    {
        startPage();
        List<CustPlan> list = custPlanService.selectCustPlanList(custPlan);
        return getDataTable(list);
    }

    /**
     * 导出客户意向列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustPlan:export')")
    @Log(title = "客户意向", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustPlan custPlan)
    {
        List<CustPlan> list = custPlanService.selectCustPlanList(custPlan);
        ExcelUtil<CustPlan> util = new ExcelUtil<CustPlan>(CustPlan.class);
        util.exportExcel(response, list, "客户意向数据");
    }

    /**
     * 获取客户意向详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustPlan:query')")
    @GetMapping(value = "/{planid}")
    public AjaxResult getInfo(@PathVariable("planid") Long planid)
    {
        return AjaxResult.success(custPlanService.selectCustPlanByPlanid(planid));
    }

    /**
     * 新增客户意向
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustPlan:add')")
    @Log(title = "客户意向", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustPlan custPlan)
    {
        return toAjax(custPlanService.insertCustPlan(custPlan));
    }

    /**
     * 修改客户意向
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustPlan:edit')")
    @Log(title = "客户意向", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustPlan custPlan)
    {
        return toAjax(custPlanService.updateCustPlan(custPlan));
    }

    /**
     * 删除客户意向
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustPlan:remove')")
    @Log(title = "客户意向", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planids}")
    public AjaxResult remove(@PathVariable Long[] planids)
    {
        return toAjax(custPlanService.deleteCustPlanByPlanids(planids));
    }
}
